import java.io.*;
import java.util.StringTokenizer;

/**
 * Created with IntelliJ IDEA.
 * Description: 维护最大值，且支持范围查询的线段树
 * User: DELL
 * Date: 2024-05-21
 * Time: 21:43
 */
public class Main2 {
    static int MAXN = 100001;
    static long[] arr = new long[MAXN];
    static long[] sum = new long[MAXN << 2];
    static long[] add = new long[MAXN << 2];

    /**
     * 累加和信息的汇总
     */
    private static void up(int i) {
        // 父范围的累加和 = 左范围的累加和 + 右范围的累加和
        sum[i] = sum[i << 1] + sum[i << 1 | 1];
    }

    /**
     * 懒更新
     *
     * @param i 更新节点下标
     * @param v 更新值
     * @param n 节点个数
     */
    private static void lazy(int i, long v, int n) {
        sum[i] += v * n;
        add[i] += v;
    }

    /**
     * 懒信息下发
     *
     * @param i  当前节点下标
     * @param ln 左侧节点个数
     * @param rn 右侧节点个数
     */
    private static void down(int i, int ln, int rn) {
        if (add[i] != 0) {
            // 发左
            lazy(i << 1, add[i], ln);
            // 发右
            lazy(i << 1 | 1, add[i], rn);
            // 父亲懒信息清空
            add[i] = 0;
        }
    }

    /**
     * 建树
     *
     * @param i
     * @param l
     * @param r
     */
    private static void build(int i, int l, int r) {
        if (l == r) {
            sum[i] = arr[l];
            return;
        }
        int mid = (l + r) >> 1;
        build(i << 1, l, mid);
        build(i << 1 | 1, mid + 1, r);
        up(i);
        add[i] = 0;
    }

    /**
     * 范围修改
     */
    private static void update(int jobL, int jobR, long jobV, int l, int r, int i) {
        if (jobL <= l && r <= jobR) {
            lazy(i, jobV, r - l + 1);
        } else {
            int mid = (l + r) >> 1;
            // 先将懒信息下发
            down(i, mid - l + 1, r - mid);
            if (jobL <= mid) {
                update(jobL, jobR, jobV, l, mid, i << 1);
            }
            if (mid < jobR) {
                update(jobL, jobR, jobV, mid + 1, r, i << 1 | 1);
            }
            // 信息汇总
            up(i);
        }
    }

    /**
     * 范围查询
     */
    private static long query(int jobL, int jobR, int l, int r, int i) {
        if (jobL <= l && r <= jobR) {
            return sum[i];
        } else {
            int mid = (l + r) >> 1;
            down(i, mid - l + 1, r - mid);
            long res = 0;
            if (jobL <= mid) {
                res += query(jobL, jobR, l, mid, i << 1);
            }
            if (mid < jobR) {
                res += query(jobL, jobR, mid + 1, r, i << 1 | 1);
            }
            return res;
        }
    }

    public static void main(String[] args) throws IOException {
        int n = in.nextInt();
        int m = in.nextInt();
        for (int i = 1; i <= n; i++) {
            arr[i] = in.nextLong();
        }
        // 先建树
        build(1, 1, n);
        while (m-- > 0) {
            int choice = in.nextInt();
            if (choice == 1) {
                int l = in.nextInt();
                int r = in.nextInt();
                long v = in.nextLong();
                update(l, r, v, 1, n, 1);
            } else {
                int l = in.nextInt();
                int r = in.nextInt();
                out.write(query(l, r, 1, n, 1) + "\n");
            }
        }
        out.close();
    }

    static InputReader in = new InputReader();
    static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));

    static class InputReader {
        private StringTokenizer st;
        private BufferedReader bf;

        public InputReader() {
            bf = new BufferedReader(new InputStreamReader(System.in));
            st = null;
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) {
                st = new StringTokenizer(bf.readLine());
            }
            return st.nextToken();
        }

        public String nextLine() throws IOException {
            return bf.readLine();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

    }
}
